package com.groupname.dangerousdelves;

import java.io.IOException;
import java.io.BufferedReader;
import java.util.ArrayList;

/**
 *  This class holds and manages the actual tiles that make up a dungeon.
 *
 *  @author Chris Fieldman (chrisf90)
 *  @version 2012.11.03
 */
public class Dungeon
{
    //~-------------------------------------------------------------------------
    // Member Variables
    private int width;
    private int height;

    private ArrayList<ArrayList<IActor>> cells;

    private DungeonListener listener;

    //~-------------------------------------------------------------------------
    // Constructors
    /**
     * Create a new Dungeon object.
     */
    public Dungeon()
    {
        cells = new ArrayList<ArrayList<IActor>>();

        //this.listener = new DungeonListener(this);
        //EventManager.addListener(EventType.OpenDoor, this.listener);
    }

    //~-------------------------------------------------------------------------
    // Methods
    /**
     * Place a description of your method here.
     * @param file
     */
    public void load(String file)
    {
        try
        {
            BufferedReader reader = DangerousDelvesGame.fileIO.readAsset(file);
            String line = reader.readLine();
            ActorSelector selector = new ActorSelector();

            while (line != null)
            {
                ArrayList<IActor> row = new ArrayList<IActor>();
                for (int i = 0; i < line.length(); i++)
                {
                    IActor actor = selector.createActor(line.charAt(i));
                    row.add(actor);
                }

                this.cells.add(row);
                line = reader.readLine();
            }
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}